package org.magnerfuller.imtoolkit.server.session;

import org.magnerfuller.imtoolkit.server.service.ServiceBackend;
import org.magnerfuller.imtoolkit.server.service.ServiceDescription;
import org.magnerfuller.imtoolkit.server.service.ServiceFactory;
import org.magnerfuller.imtoolkit.server.session.medium.SessionDescription;
import org.magnerfuller.imtoolkit.server.session.medium.SessionMedium;

public class SessionFactory {
  
  private static SessionFactory me;
  
  public static SessionFactory getInstance() {
    
    if(me == null) {
      me = new SessionFactory();
    }
    
    return me;
  }
  
  public Session createSession(ServiceDescription serviceDesc,
                               SessionDescription sessionDesc) {
    
    Session session;
    
    ServiceBackend backend = ServiceFactory.getInstance().createService(serviceDesc);
    SessionMedium medium = sessionDesc.getMedium();
    
    if(backend == null) {
      System.err.println("SessionFactory: backend is null!");
    }
    if(medium == null) {
      System.err.println("SessionFactory: medium is null!");
    }
    
    if(backend == null || medium == null) {
      session = null;
    }
    else {
      session = new Session(backend, medium);
    }
    
    return session;
    
  }

}
